package com.example.demo.controller;


import com.example.demo.entity.SaveCC;
import com.example.demo.service.PictureCcService;
import com.example.demo.service.SaveCCService;
import com.example.demo.service.VideoCcService;
import com.example.demo.service.VoiceCcService;
import com.example.demo.vo.DataView;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Slf4j
@RestController
@RequestMapping(value = "/drafts")
public class DraftsReceiverOrSendController {



    @Autowired
    private SaveCCService saveCCService;

    @Autowired
    private VoiceCcService voiceCcService;

    @Autowired
    private PictureCcService pictureCcService;

    @Autowired
    private VideoCcService videoCcService;

    @RequestMapping(value = "/save")
    public DataView receiveLetter(@RequestBody SaveCC saveCC, HttpServletRequest request)
    {

        return saveCCService.receiveLetter(saveCC,request);
    }

    /**
     * 接收图片
     */
    @PostMapping(value = "/receiveImages")
    public DataView receivesQRCodePictures(@RequestParam(value = "images") MultipartFile[]images, HttpServletRequest request) throws IOException {

        return saveCCService.receivePictures(images,request);
    }

    /**
     * 接收视频
     */
    @RequestMapping(value = "/receiveVideos")
    public DataView receiveVideos(@RequestParam(value = "videos") MultipartFile []videoFiles,HttpServletRequest request) throws IOException {

        return saveCCService.receiveVideos(videoFiles,request);


    }

    @RequestMapping(value = "/receiveVoice")
    public DataView receiveVoice(@RequestParam(value = "voice")MultipartFile voiceFile,HttpServletRequest request) throws IOException{
        return saveCCService.receiveVoice(voiceFile,request);
    }

    /**
     * 发送基本信息
     */

    @RequestMapping(value = "/send")
    public DataView send(HttpServletRequest request)
    {
        return saveCCService.send(request);
    }

    @RequestMapping(value="/sendPicture")
    public DataView sendPicture(HttpServletRequest request)
    {
        return saveCCService.sendPicture(request);
    }

    @RequestMapping(value = "/sendVoice")
    public DataView sendVoice(HttpServletRequest request)
    {
        return saveCCService.sendVoice(request);
    }

    @RequestMapping(value = "/sendVideo")
    public DataView sendVideo(HttpServletRequest request)
    {
        return saveCCService.sendVideo(request);
    }

}
